#include <vector>
class Solution
{
public:
	bool isValidSudoku(std::vector<std::vector<char>>& board)
	{
		int row_used[9] = { 0 }, col_used[9] = {0}, block_used [9]= {0};

		int n = board.size();
		for(int row=0; row<n; ++row)
			for (int col = 0; col < n; ++col)
			{
				char& ch = board[row][col];
				if (ch == '.')
					continue;

				int& row_flag = row_used[row];
				int& col_flag = col_used[col];
				int& block_flag = block_used[row / 3 * 3 + col/3];
				int shift =1<< (ch - '0');
				if (row_flag & shift ||
					col_flag & shift ||
					block_flag & shift)
					return false;

				row_flag |= shift;
				col_flag |= shift;
				block_flag |= shift;
			}
		return true;
	}
};
